<%@ page language="java" pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/view/common/common.jsp" %>
<!doctype html>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="${ctx}/resources/mallcss/initcss.css" rel="stylesheet">
    <link href="${ctx}/resources/mallcss/common.css" rel="stylesheet">
    <style>

        .con {
            background-color: #e8e8e8;
        }

        header {
            background: #f03791;
            height: 3.7em;
            text-align: center;
            position: relative;
        }

        .Return, .Home {
            position: absolute;
            width: 3.7em;
            height: 3.7em;
        }

        .Return {
            left: 0;
        }

        .Home {
            right: 0;
        }

        .Return span, .Home span {
            background: url("${ctx}/resources/mallimages/png.png");
            background-size: 17em;
            position: absolute;
            width: 1.7em;
            height: 1.7em;
        }

        .Return span {
            background-position: -0.17em -5.5em;
            left: 1em;
            top: 1em;
        }

        .Home span {
            background-position: -0.17em -8.1em;
            left: 1em;
            top: 1em;
        }

        .Title {
            color: white;
            font-size: 1.3em;
            line-height: 2.7em;
        }

        .login section {
            padding: 0.8em 0.8em;
        }

        .input {
            background: #ffffff;
            border-radius: 4px;
            border: #dadada 1px solid;
            -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .1) inset;
        }

        .name {
            padding: 0.3em 0.5em;
            /*overflow: hidden;*/
            position: relative;
            line-height: 2.3em;
            font-size: 1.1em;
            border-bottom: 1px solid #e3e3e3;
        }

        .name b {
            color: #85858d;
            text-align: center;
            font-size: 1.2em;
            line-height: 1.8em;
            position: absolute;
            left: 0.5em;
            top: 0.5em;
        }

        .name span {
            display: block;
            /*position: static;*/
            padding-left: 4em;

        }

        .name span input {
            border: none;
            width: 100%;
            padding: 0;
            height: 2.3em;
            font-size: 1.2em;
            outline: none;
        }

        .loginBtn {
            display: block;
            background: #f02387;
            width: 100%;
            border-radius: 1em;
            color: white;
            text-align: center;
            font-size: 1.5em;
            margin-top: 1.5em;
            padding: 0.7em 0;
            margin-bottom: 0.5em;
        }

        .hz {
            border-top: 1px white solid;
            text-align: center;
            padding: 1em;
            margin-top: 1em;
        }

        .hz h2 {
            margin-top: -1.3em;
        }

        .hz h2 span {
            background: #e8e8e8;
            color: #5e5e5e;
            font-size: 0.8em;
        }

        .hz p {
            padding: 1em;
            text-align: center;
        }

        .hz p img {
            margin-right: 0.3em;
            width: 2.1em;
        }


    </style>
    <title>重置密码</title>
</head>
<body style="background: rgb(232, 232, 232);">
<div class="con">
    <a href="" class="Home"><span></span></a>
        <form id="loginForm">
            <div class="login">
                <section>
                    <div class="input">
                        <div class="name">
                            <b>邮箱：</b><span><input id="mailbox" name="mailbox" placeholder="邮箱" type="text"></span>
                        </div>
                        <div class="name">
                            <b>密码：</b><span><input id="password" name="password" placeholder="新密码" type="password"></span>
                        </div>
                        <div class="name">
                            <b>重复：</b><span><input id="rePaw" name="rePaw" placeholder="重复密码" type="password"></span>
                        </div>
                        <div class="name">
                            <b>验证：</b><span><input style="width: 100px;" id="reCode" placeholder="邮箱验证码" name="reCode" type="text"></span>
                        </div>
                    </div>
                    <p>
                        <label class="loginBtn"  id="wjmmBtn">重置密码</label>
                </section>
            </div>
        </form>
    <label class="loginBtn"  id="hqyzm">获取验证码</label>
    <%--<span style="padding-left: 200px;"><button style="line-height: 23px;background-color: #d0cdff;" id="hqyzm">获取验证码</button></span>--%>
    <div class="hz">
    </div>
</div>

<jsp:include page="footer.jsp"/>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery.form/4.2.1/jquery.form.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-validate/1.16.0/additional-methods.min.js"></script>

</body>
<script>
    $(function () {
        $("#wjmmBtn").on('click', function () {
            var mailbox = document.getElementById("mailbox").value;
            var password = document.getElementById("password").value;
            var rePaw = document.getElementById("rePaw").value;
            var reCode = document.getElementById("reCode").value;
            if(mailbox == "" && mailbox.length == 0) {
                alert("请输入邮箱!");
            }else if(password == "" && password.length == 0){
                alert("请输入密码!");
            }else if(rePaw == "" && rePaw.length == 0){
                alert("请再次输入密码!");
            }else if(reCode == "" && reCode.length == 0){
                alert("请输入邮箱验证码!");
            }else if(rePaw!=password){
                alert("两次输入的密码不一致!");
            }else {
                var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                if(!reg.test(mailbox)) {
                    alert("邮箱格式不正确!");
                }else if(password.length < 6){
                    alert("密码长度最少为6位!")
                }else{
                    <%--var StrNum = "<%=request.getSession().getAttribute("code")%>";--%>
                    <%--alert(StrNum);--%>
                    // if(StrNum == reCode){
                        var url = "<c:url value="/dmz/mobile/wjmmJson.json" />";
                        if (confirm("温馨提示：确认重置密码吗？")) {
                            $.ajax({
                                url: url,
                                type: 'post',
                                data: {
                                    mailbox : mailbox,
                                    password : password,
                                    reCode : reCode
                                },
                                dataType: 'json',
                                success: function (data) {
                                    if(data.flag==0) {
                                        alert("密码重置成功");
                                        window.location.href = "<c:url value="/mobile/wxLogin.html"/>";
                                    }else{
                                        alert("密码重置失败：原因1.邮箱不存在。2.存在多个邮箱异常。3.验证码不匹配。");
                                    }
                                }
                            });
                            // alert("密码重置成功！");
                            <%--window.location.href="<c:url value="/mobile/wxLogin.html"/>";--%>
                        }
                    // }else{
                    //     alert("邮箱验证码错误!");
                    // }
                }
            }
        });
    });
    $(function () {
        $("#hqyzm").on('click', function () {
            var mailbox = document.getElementById("mailbox").value;
            if(mailbox == "" && mailbox.length == 0) {
                alert("请输入邮箱!");
            }else {
                var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                if(!reg.test(mailbox)) {
                    alert("邮箱格式不正确!");
                }else{
                    var url = "<c:url value="/dmz/mobile/send.json" />";
                    $.ajax({
                        url: url,
                        type: 'get',
                        data: {
                            mailbox : mailbox
                        },
                        dataType: 'json',
                        success: function (data) {
                            if(data.flag==0) {
                                alert("发送成功!去邮箱查看验证码吧。");
                            }else{
                                alert("发送失败!邮箱无效。");
                            }
                        }
                    });
                }
            }
        });
    });
</script>
</html>